<%@ page import="com.wy.util.DBUtil" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 13939
  Date: 2024/11/28
  Time: 11:36
  To change this template use File | Settings | File Templates.
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新闻发布</title>
    <link rel="stylesheet" href="../styles/newStyles.css">
    <script src="../scripts/news.js"></script>
</head>
<body>
<%
    //检测用户是否已经登陆了
    String username  = (String) session.getAttribute("username");
    String hid = request.getParameter("hid");
    if(username==null){
        response.sendRedirect("/login/login.jsp");
        return;  //!!!!!不能少  返回  不执行下面的语句
    }else{
        String sql="select * from news_headline where hid = "+hid;

        DBUtil dbUtil=new DBUtil();
        ResultSet query = dbUtil.query(sql);
        query.next();
        String title = query.getString("title");
        String article = query.getString("article");
        int type = query.getInt("type");
        String sql1="select tname from news_type where tid = "+type;
        ResultSet query1 = dbUtil.query(sql1);
        query1.next();
        String tname = query1.getString("tname");


%>

<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <form action="updateNew.jsp?hid=<%=hid%>" method="post" onsubmit="return news()">
                <div class="form-group">
                    <label for="newsTitle">文章标题</label>
                    <input type="text" class="form-control" id="newsTitle" name="newsTitle" value="<%= title %>" required>
                </div>
                <div class="form-group">
                    <label for="newsContent">文章内容</label>
                    <textarea class="form-control" id="newsContent" name="newsContent" rows="5"  required><%= article %></textarea>
                </div>
                <div class="form-group">
                    <label for="newsCategory">文章类别</label>
                    <select class="form-control" id="newsCategory" name="newsCategory">
                        <option value="<%= type %>"><%= tname %></option>
                        <option value="1">新闻</option>
                        <option value="2">体育</option>
                        <option value="3">娱乐</option>
                        <option value="4">科技</option>
                        <option value="5">其他</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">保存</button>
                <a href="../show/show.jsp" class="btn btn-secondary ml-2">取消</a>
                <div id="error-message" style="color: red;"></div>
            </form>
        </div>
    </div>
</div>

</body>
<%}%>
</html>
